home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 9 / CDACTUAL9.iso / share / Dos / VARIOS / pascal / SWAG9605.DDD / 0059_Copy Multiple files to any dir.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-05-31  |  4.2 KB  |  186 lines

  1. {
  2. MULTI COPY
  3.  
  4. This program will copy multiple files to a specified area. I
  5. hope that this shit works too.
  6.  
  7. This program cannot copy files to a single file nor can it be
  8. expected to know the difference between a file and a directory;
  9.  
  10. Therefore you must append a back-slash if copying
  11. into a directory.
  12.  
  13. Example: To Copy COMMAND.COM into C:\tp7\code\work
  14.  
  15. You'd use MCOPY COMMAND.COM C:\tp7\code\work\
  16. }
  17.  
  18. Program Mcopy;
  19.  
  20. Uses dos;
  21.  
  22.  
  23. {$R+}
  24.  
  25.  
  26. Procedure Usage;
  27. Begin
  28.      Writeln;
  29.      Writeln('Multiple File Copier  (C) 1995 Scott Tunstall. ');
  30.      Writeln;
  31.      Writeln('Usage :');
  32.      Writeln;
  33.      Writeln('MCOPY <FileSpec1> [..FileSpec2] [..FileSpec3 etc.]  <DestSpec>');
  34.      Writeln;
  35.      Writeln;
  36.      Writeln('You can copy as many different types of file in one go as can');
  37.      Writeln('fit on one line just as long as you specify a destination, ');
  38.      Writeln('which must ALWAYS be the last parameter.');
  39.      Writeln;
  40.      Writeln('Also, make sure that if you are copying to a directory that a "\"');
  41.      Writeln('is appended to the directory name otherwise the copy will FAIL !.');
  42.      Writeln;
  43.      Writeln('Example: C:\WORK should be C:\WORK\ with this program.');
  44.      Writeln;
  45. End;
  46.  
  47.  
  48. Procedure Error;
  49. Begin
  50.      Writeln;
  51.      Writeln('You need to specify at least two parameters, a source and a');
  52.      Writeln('destination! ');
  53.      Writeln;
  54.      Writeln('Type MCOPY ? for help.');
  55.      Writeln;
  56. End;
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63. Function CopyFile(SourceFile, TargetFile : String): Byte;
  64. { Return codes:  0 successful
  65.                  1 source and target the same
  66.                  2 cannot open source
  67.                  3 unable to create target
  68.                  4 error during copy
  69. }
  70. Var
  71.   Source,
  72.   Target  : File;
  73.   BRead,
  74.   BWrite  : Word;
  75.   FileBuf : Array[1..2048] of Char;
  76. begin
  77.   If SourceFile = TargetFile then
  78.   begin
  79.     CopyFile := 1;
  80.     Exit;
  81.   end;
  82.  
  83.   Assign(Source,SourceFile);
  84.   {$I-}
  85.   Reset(Source,1);
  86.   {$I+}
  87.   If IOResult <> 0 then
  88.   begin
  89.     CopyFile := 2;
  90.     Exit;
  91.   end;
  92.  
  93.  
  94.  
  95.   Assign(Target,TargetFile);
  96.   {$I-}
  97.   ReWrite(Target,1);
  98.   {$I+}
  99.   If IOResult <> 0 then
  100.   begin
  101.     CopyFile := 3;
  102.     Exit;
  103.   end;
  104.  
  105.  
  106.   Repeat
  107.     BlockRead(Source,FileBuf,SizeOf(FileBuf),BRead);
  108.     BlockWrite(Target,FileBuf,Bread,BWrite);
  109.   Until (Bread = 0) or (Bread <> BWrite);
  110.   Close(Source);
  111.   Close(Target);
  112.   If Bread <> BWrite then
  113.     CopyFile := 4
  114.   else
  115.     CopyFile := 0;
  116. end; {of func CopyFile}
  117.  
  118.  
  119.  
  120.  
  121. Procedure BeginCopying;
  122. Var DestinationSpec: PathStr;
  123.     SourceCount: byte;
  124.     SourceFileSpec: PathStr;
  125.     SearchRecord: SearchRec;
  126.     Errorcode: byte;
  127.  
  128. Begin
  129.      DestinationSpec:=ParamStr(ParamCount);
  130.  
  131.      For SourceCount:=1 to ParamCount-1 do
  132.          Begin
  133.          SourceFileSpec:=ParamStr(SourceCount);
  134.          FindFirst(SourceFileSpec,$27,SearchRecord);
  135.  
  136.          If DosError <>0 Then
  137.             Begin
  138.             Writeln;
  139.             Writeln('Cannot open source file(s) !');
  140.             Writeln;
  141.             End
  142.          Else
  143.              Begin
  144.              Repeat
  145.                    Write(SearchRecord.Name,'..');
  146.                    ErrorCode:=CopyFile(SearchRecord.Name,DestinationSpec+SearchRecord.Name);
  147.  
  148.                    If ErrorCode<>0 Then
  149.                       Begin
  150.                       Write('Error (',ErrorCode,') : ');
  151.                       Case ErrorCode Of
  152.                       1: Writeln('Source and destination are the same !');
  153.                       2: Writeln('Cannot open source file(s) !');
  154.                       3: Writeln('Unable to create destination file(s) !');
  155.                       4: Writeln('Copying error. Check disk integrities !');
  156.                       End;
  157.                       End
  158.                    Else
  159.                        Writeln('copied.');
  160.  
  161.  
  162.                    FindNext(SearchRecord);
  163.  
  164.              Until DosError <>0;
  165.  
  166.              Writeln;
  167.              Writeln('Operation Complete. ');
  168.              Writeln;
  169.              End;
  170.      End;
  171. End;
  172.  
  173.  
  174.  
  175.  
  176. Begin
  177.      If ParamStr(1)='?' Then
  178.         Usage
  179.      Else
  180.          If ParamCount <2 Then
  181.             Error
  182.          Else
  183.              BeginCopying;
  184. End.
  185.  
  186.